/** CODE EVALL::Moderate [Prime Numbers]
 *	Print out the prime numbers less than a given number N. For bonus points your 
 *	solution should run in N*(log(N)) time or better. You may assume that N is 
 *	always a positive integer.
 *
 *	Solution by Michael Pio Arroyo
 */

#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>

bool isPrime(int n);

int main(int argc, char** argv) {
	std::ifstream file;
	std::string line;
	file.open(argv[1]);
	while(getline(file, line)) {
		std::string t;
		std::string s;
		std::string::iterator it = line.begin();
		// get input number
		while(it != line.end()) {
			t = *it;
			s.append(t);
			++it;
		}
		int in = atoi(s.c_str());

		std::cout << 2 << ',' << 3;

		for(int i=5; i<=in; ++i) {
			isPrime(i);
		}
		
		putchar('\n');
		s.clear();
	}

	file.close();
	return 0;
}

bool isPrime(int n) {
	if((n%2) == 0)
		return false;
	if((n%3) == 0)
		return false;
	for(int i=3; i<(n/2); i+=2) {
		if((n%i) == 0)
			return false;
	}
	std::cout << ',' << n;
	return true;
}